﻿using RxxApi.IServices.System;
using RxxApi.Model.Entity;
using RxxApi.Repository.BASE;
using RxxApi.Services.BASE;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RxxApi.Services.System;

public class SysMenuService : BaseServices<SysMenu>, ISysMenuService
{
    private readonly IBaseRepository<SysUserRole> _userRoleRepository;
    private readonly IBaseRepository<SysRoleMenu> _roleMenuRepository;

    public SysMenuService(IBaseRepository<SysUserRole> userRoleRepository,
        IBaseRepository<SysRoleMenu> roleMenuRepository)
    {
        _userRoleRepository = userRoleRepository;
        _roleMenuRepository = roleMenuRepository;
    }
    public async Task<List<SysMenu>> GetMenuInfoByUserId(long uid)
    {
        var rid = (await _userRoleRepository.Query(x => x.UserId == uid)).Select(x => x.RoleId);
        var mids = (await _roleMenuRepository.Query(x => x.RoleId == Convert.ToDouble(rid))).Select(x => x.MenuId).ToList();
        object[] objectArray = new object[mids.ToArray().Length];
        Array.Copy(mids.ToArray(), objectArray, mids.ToArray().Length);
        var menus = (await QueryByIDs(objectArray));
        return menus;
    }
}
